package servlet;

import java.io.*;
import java.util.*;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import mgr.OrdenPedidoManager;
import to.OrdenPedidoTO;

@SuppressWarnings("serial")
public class VerRepPedidosAction extends HttpServlet {
    
    public void doGet(HttpServletRequest req, HttpServletResponse resp)
        throws ServletException, IOException {
        procesar(req, resp);
    }
    
    public void doPost(HttpServletRequest req, HttpServletResponse resp)
        throws ServletException, IOException {
        procesar(req, resp);
    }

    private void procesar(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        String nOrdenPedido = req.getParameter("nOrdenPedido");
        String cCliente = req.getParameter("cCliente");
        String fOrdenPedido1 = req.getParameter("fOrdenPedido1");
        //String fOrdenPedido2 = req.getParameter("fOrdenPedido2");
        String cEstado = req.getParameter("cEstado");
        
        try {
            
            List<OrdenPedidoTO> listadoOrdenes;
            OrdenPedidoTO ord_to = new OrdenPedidoTO(nOrdenPedido, cCliente, fOrdenPedido1, cEstado, "", 0, 0, 0, 0, "", "", "", "");
            OrdenPedidoManager ordenes = new OrdenPedidoManager();
            listadoOrdenes = ordenes.filtraPedidos(ord_to);
                        
            HttpSession sesion = req.getSession();
            sesion.setAttribute("listadoOrdenes", listadoOrdenes);
            
            getServletContext().getRequestDispatcher("/Reporte_Pedidos.jsp").forward(req, resp);
            
        }
        catch (Exception e) {
            PrintWriter out = resp.getWriter();
            out.println("<HTML>");
            out.println("<HEAD>");
            out.println("</HEAD>");
            out.println("<BODY>");

            String msg = (String) e.getMessage();
            out.println("<P>" + msg + "</P>");

            out.println("</BODY>");
            out.println("</HTML>");
	}
    }
}